fix: guard against empty Build.Image in ImageNameWithDigest#3905
fix: guard against empty Build.Image in ImageNameWithDigest#3905Elvand-Lie wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Elvand-Lie The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @Elvand-Lie. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Verification Evidence1.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3905 +/- ##
==========================================
- Coverage 53.93% 51.68% -2.26%
==========================================
Files 200 200
Lines 23681 23682 +1
==========================================
- Hits 12772 12239 -533
- Misses 9674 10302 +628
+ Partials 1235 1141 -94
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ImageNameWithDigest did not validate that Build.Image is non-empty. When called with a non-empty digest but empty image name, it produced the malformed OCI reference @sha256:... (missing image name prefix), causing confusing downstream parse errors in name.ParseReference. Added early return for empty image. Fixes knative#3902
03daf3f to
b75d85e
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes Function.ImageNameWithDigest to avoid generating an invalid OCI reference (@sha256:...) when Build.Image is empty by adding an early return.
Changes:
- Add an early guard to return
""whenf.Build.Imageis empty and a digest is provided.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| image := f.Build.Image | ||
| if image == "" { | ||
| return "" | ||
| } |
| image := f.Build.Image | ||
| if image == "" { | ||
| return "" | ||
| } |
Description
ImageNameWithDigestinpkg/functions/function.godoes not validate thatBuild.Imageis non-empty before processing. When called with a non-emptynewDigestbut an empty image name, it produces the malformed OCI reference@sha256:...(missing the image name prefix), causing confusing downstreamname.ParseReferenceerrors.Added early return for empty image.
Changes
pkg/functions/function.go, line 866: addedif image == "" { return "" }guardReproduction
Verification
go vet ./pkg/functions: cleango test ./pkg/functions/ -run TestFunction_ImageWithDigest -count=1: all 5 tests passFixes #3902